package game.gamestate.debugroom.ui;

import common.Area;
import common.Rectangle;

import game.entity.EntityType_E;
import game.entity.Entity_A;
import game.entity.ui.UI_Entity;
import game.gamestate.GameState;
import game.map.MapInfo;
import game.map.block.BlockMap;
import game.physics.CollisionGroup_I;
import game.scene.Layer_E;
import game.scene.sceneobject.Container_SO;
import game.scene.sceneobject.Rectangle_SO;

public class BlockMapVisualizer extends UI_Entity {
	public BlockMapVisualizer() {
		super("blockmap_visualizer");
	}
	private Container_SO _MapVis;
	@Override
	public boolean create(GameState gameState) {
		buildMapVis(gameState);
		gameState.Scene.getLayer(Layer_E.UI).insert(_MapVis);
		return true;
	}

	@Override
	public boolean think(GameState gameState, int time) {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean update(GameState gameState, int time) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean destroy(GameState gameState) {
		gameState.Scene.getLayer(Layer_E.UI).remove(_MapVis);
		return true;
	}
	
	private void buildMapVis(GameState gameState) {
		if(_MapVis == null) {
			_MapVis = new Container_SO();
		}
		_MapVis.removeAll();
		
		CollisionGroup_I bMap = gameState.GameMap.getBlockMap();
		Area[] cells = bMap.getObstacles();
		Rectangle_SO rect;
		for(Area cell : cells) {
			if(cell != null) {
				rect = new Rectangle_SO();
				rect.Color = (byte)0x0F;
				rect.setBoundry(cell.Boundary);
				rect.setLocation(cell.Location);
				_MapVis.add(rect);
			}
		}
	}

}
